package JAVA300.第六章异常;
/*
测试自定义异常
 */



public class TestExceptionDef {
    public static void main(String[] args) throws IllegalAgeException {
        Person p = new Person();
        p.setAge(-10);

    }
}

class Person{
    private int age;

    public void setAge(int age) throws IllegalAgeException {
        if (age<0){
            throw new IllegalAgeException("年龄不能<0");
        }
        this.age = age;
    }
}

class IllegalAgeException extends Exception{
    public IllegalAgeException(){
    }
    public IllegalAgeException(String msg){
        super(msg);

    }
}
